home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / AMOSCOMP.DMS / in.adf / Sample_Double_Buffering.AMOS / Sample_Double_Buffering.amosSourceCode
Encoding:
AMOS Source Code  |  1993-02-25  |  3.3 KB  |  140 lines

  1. '-----------------------------------------------------------------------------   
  2. ' Sample Double Buffering example  
  3. ' By Fran�ois Lionet 
  4. ' AMOS (c) Europress Software 1990/91  
  5. '----------------------------------------------------------------------------- 
  6. '
  7. ' This example show the use of the new musical instructions
  8. ' SAM SWAP and SAM SWAPPED to play samples of any length 
  9. ' directly from the disc.
  10. ' This example will only work with a hard-drive, or a CD-ROM 
  11. ' player. Well, it may be possible to play at a very low 
  12. ' rate, like 3000 Herz, with a disgusting result, from a floppy. 
  13. '
  14. ' First thing to do: create or grab a big sample, and save it  
  15. ' with the name "SAMPLE.SAM" 
  16. '  
  17. '----------------------------------------------------------------------------- 
  18. '
  19. ' First, we must reserve two memory banks in CHIP RAM. Two, because
  20. ' we are double buffering. No need to choose banks too long. The 
  21. ' longer the banks, the longer the delay between each load will
  22. ' be.
  23. ' You can start with as little as 8 K per buffer.
  24. '
  25. LBANK=1024*8
  26. '
  27. ' Lets reserve.
  28. '
  29. Reserve As Chip Work 10,LBANK
  30. Reserve As Chip Work 11,LBANK
  31. '
  32. ' Lets define the voices used to play the sample.
  33. ' First, the bitpattern, then the voice used to test the swap. 
  34. V=%11 : VX=0
  35. '
  36. ' Replay frequeny
  37. '
  38. FREQ=10000
  39. '
  40. ' Open the sample, with a simple OPEN IN.  
  41. '
  42. F$="Sample.Sam"
  43. '
  44. Open In 1,F$
  45. '
  46. ' Get the length of the file, once for all. You should avoid 
  47. ' the use of =POF and =LOF while you are playing the sample, as
  48. ' they move the head.
  49. LSAM=Lof(1)
  50. '
  51. ' Maxximum volume! 
  52. '
  53. Volume 63
  54. '
  55. ' Lets load the first part of the sample in the first bank,
  56. ' with the new fabulous instruction, SLOAD 
  57. '  
  58. Sload 1 To Start(10),LBANK
  59. '
  60. ' You must launch the sample with SAM RAW. This instruction
  61. ' set the replay rate for all the sample.
  62. '
  63. Sam Raw V,Start(10),LBANK,FREQ
  64. '
  65. ' Calculate the remaining length.
  66. '
  67. LSAM=LSAM-LBANK
  68. '
  69. ' Flipping buffer indicator. 
  70. '
  71. PSAM=1
  72. '
  73. ' This is the sample-swapping loop. Of course, this loop 
  74. ' mainly does nothing. In a program, you can call you graphic output 
  75. ' routines, and just check for the sample-swapping from time 
  76. ' to time, with a specific procedure...
  77. '
  78. ' While we have something to load... 
  79. '  
  80. While LSAM>0
  81.    '
  82.    Repeat 
  83.       '
  84.       ' A small delay loop when you press a mousekey, to 
  85.       ' simulate an out-of-sync : the sample will stop for a 
  86.       ' moment.
  87.       ' This could happend if you do not check for the sample-swapping 
  88.       ' frequently enough... 
  89.       '  
  90.       While Mouse Key : Wend 
  91.       '  
  92.       ' Nice multitask wait. 
  93.       Multi Wait 
  94.       '
  95.       ' The loop will exit when you can load another 
  96.       ' part of the sample...
  97.       '
  98.       P=Sam Swapped(VX)
  99.       '
  100.    Until P
  101.    '
  102.    ' How long left to load? 
  103.    '
  104.    LLOAD=Min(LSAM,LBANK)
  105.    '
  106.    ' Lets load the bits.
  107.    Sload 1 To Start(10+PSAM),LLOAD
  108.    '
  109.    ' Initialise the newly loaded buffer.
  110.    '
  111.    If P=-1
  112.       '
  113.       ' We are still synchronised, we can do a nice
  114.       ' sample-swap. 
  115.       '
  116.       Sam Swap V To Start(10+PSAM),LLOAD
  117.       '
  118.    Else 
  119.       '
  120.       ' Oops, to late! We have to restart the sample.
  121.       '
  122.       Sam Raw V,Start(10+PSAM),LLOAD,FREQ
  123.       '
  124.    End If 
  125.    '
  126.    ' Count how much left to load. 
  127.    '
  128.    LSAM=LSAM-LLOAD
  129.    '
  130.    ' Flip the buffers.
  131.    '  
  132.    PSAM=1-PSAM
  133.    '
  134.    ' Exit if any key pressed. 
  135.    If Inkey$<>"" : Sam Stop : Exit : End If 
  136.    '
  137. Wend 
  138. '
  139. ' Close the file.
  140. Close